package com.ee.chat.cps.admin.service.impl;

import com.ee.chat.common.dao.ChannelOperationLogMapper;
import com.ee.chat.common.entity.Channel;
import com.ee.chat.common.entity.ChannelOperationLog;
import com.ee.chat.cps.admin.service.IChannelOperationService;
import com.ndhutu.ee.util.IPUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author AppiJ
 * @Date 2020/4/15 19:17
 */
@Service
public class ChannelOperationServiceImpl implements IChannelOperationService {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    ChannelOperationLogMapper channelOperationLogMapper;

    /**
     * 添加渠道后台操作记录
     * @Author AppiJ
     * @Date 2020/4/15 19:19
     * @param
     * @return
     */
    @Override
    public void addOperationLog(HttpServletRequest request, String describe) throws Exception {
        HttpSession session = request.getSession(true);

        Channel channel = (Channel) session.getAttribute("channelUser");
        String ip = IPUtil.getClientIP(request);

        ChannelOperationLog channelOperationLog = new ChannelOperationLog(channel.getId(), ip, describe);
        channelOperationLogMapper.insert(channelOperationLog);

        log.info(channel.getUsername()+"渠道"+describe);
    }
}
